package com.itheima.demo5tcp2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ServerReader extends  Thread{
    private Socket socket;
    public ServerReader(Socket socket) {
        this.socket = socket;
    }
    //重写run方法
    @Override
    public void run() {
        try {
            //获取输入流
            InputStream is = socket.getInputStream();
            //包装输入流
            DataInputStream dis = new DataInputStream(is);
            //读取数据
            String data = dis.readUTF();
            System.out.println(data);
            System.out.println("客户端ip是"+socket.getInetAddress().getHostAddress());
            System.out.println("客户端端口是"+socket.getPort());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("客户端已退出...");
        }
    }
}
